/*
 * 案例征集
 * @Author: Chenliang(930225)
 * @Date: 2019-10-11 14:38:13
 * @LastEditors  : Chenliang(930225)
 * @LastEditTime : 2020-01-19 17:51:34
 */

import React, { Component } from 'react';
import { Select, Table, Tabs } from 'antd';
import { getReport, getRoles, getMenus, getAPP } from '../../service/report';
import { UC } from '@sdp.nd/nd-uc-sdk'
// 初始化UC
const uc = new UC({
    env: 'product'
})
const { TabPane } = Tabs; //ant 标签切换
const { Option } = Select; //ant 下拉框

class Report extends Component {
    constructor(props) {
        super(props);
        // 设置表格信息
        this.state = {
            columns: [
                {
                    title: '省市区',
                    dataIndex: 'contact_address',
                    key: 'contact_address',
                    render: text => <span> {text} </span>,
                },
                {
                    title: '数量',
                    dataIndex: 'total_count',
                    key: 'total_count',
                }
            ],
            data: [],
        };
    }
    /**
     * @description: 组件渲染后调用获取表格数据通用方法
     * @param {type} 
     */
    componentDidMount() {
        uc.isLogin().then(res => {
            // 获取当前用户及用户信息
            const account = uc.getCurrentAccount()
            account.getAccountInfo().then(accountInfo => {
                console.log('用户信息', accountInfo)
                // 获取聚合后台APP
                var appUrl = 'https://manage-portal-api.sdp.101.com/v2/apps/actions/get_by_user?auth_id=' + accountInfo.user_id + '&user_id=' + accountInfo.user_id;
                var Authmanage = uc.getAuthHeader({ url: appUrl });
                getAPP(Authmanage, appUrl).then(result => {
                    const { data } = result;
                    console.log("获取聚合后台项目", data)
                });
            })
            var AuthMenus = uc.getAuthHeader({ url: 'https://manage-portal-api.sdp.101.com/v2/apps/a10121e2-01dd-449e-9c0c-e942fb426d92/app_menus/my' });
            getMenus(AuthMenus).then(result => {
                const { data } = result;
                console.log("后台菜单权限", data)
            });
            var AuthRoles = uc.getAuthHeader({ url: 'http://rbac.sdp.101.com/v0.1/roles/my' });
            getRoles(AuthRoles).then(result => {
                const { data } = result;
                console.log("获取用户角色", data)
            });
            var AuthReport = uc.getAuthHeader({ url: 'https://haolaoshi.sdp.101.com/v0.1/cases/collections' });
            getReport(AuthReport).then(result => {
                const { data } = result;
                console.log("获取案例列表", data)
                this.setState({
                    data: [...data.items]
                });
            });
        })
    }
    render() {
        const { columns, data } = this.state;
        return (
            <div className="task-detail-box">
                <Tabs defaultActiveKey="1" onChange={this.callback}>
                    <TabPane tab="案例征集" key="1">
                        <Select style={{ width: 300 }} onChange={this.handleChange} placeholder="年份">
                            <Option value="2019">2019</Option>
                            <Option value="2018">2018</Option>
                        </Select>
                        <Table
                            columns={columns}
                            dataSource={data}
                            onChange={this.onChangeTable}
                        />
                    </TabPane>
                </Tabs>
            </div>
        );
    }
}

export default Report;
